package zjc.案例练习;

public class 数组元素的复制 {
    public static void main(String[] args) {
        int[]arr={11,22,33,44};
        int[]arr2=arr;//没有完成数组赋值
        int[]arr3=new int[arr.length];
        copy(arr,arr3);
        shuchu(arr);
        shuchu(arr3);
        shuchu(arr2);//只是arr和arr2指向了同一个地址
        System.out.println(arr);
        System.out.println(arr2);
        System.out.println(arr3);
    }
    public static void copy(int[] a1,int[] a2){
        for (int i = 0; i < a1.length; i++) {
            a2[i]=a1[i];
        }
    }
    public static void shuchu(int[]a){
        System.out.print("{");
        for (int i = 0; i < a.length; i++) {
            System.out.print(i==a.length-1?a[i]:a[i]+", ");
        }
        System.out.println("}");
    }
}
